package com.ynkbny.tasks;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ynkbny.aspect.TaskOperationLog;
import com.ynkbny.domain.Enterprise;
import com.ynkbny.lgapi.User;
import com.ynkbny.mapper.EnterpriseMapper;
import com.ynkbny.service.BaseJob;
import com.ynkbny.service.EnterpriseService;
import com.ynkbny.service.TEpDataCollectConfigureService;
import com.ynkbny.service.TokenService;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @Author YY
 * @Date 2023/9/21
 */
@Component
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class UpdateDataCollectConfigureOneByProId implements BaseJob {

    private static final Logger log = LoggerFactory.getLogger(UpdateToken.class);

    @Resource
    private EnterpriseService enterpriseService;

    @Resource
    private TEpDataCollectConfigureService dataCollectConfigureService;

    /**
     * 通过社会信用代码同步单个企业的老狗平台上的采集配置项
     * @Author YY
     */
    @Override
    @TaskOperationLog(description = "通过社会信用代码同步单个企业的老狗平台上的采集配置项")
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        //传递的参数
        JobDataMap data = jobExecutionContext.getTrigger().getJobDataMap();

        try {
            String proId = enterpriseService.getBaseMapper().selectOne(
                    new LambdaQueryWrapper<Enterprise>().eq(Enterprise::getEnterpriseCode, data.getString("invokeParam"))
            ).getEnterpriseId();
            // 从老狗平台拉取采集配置项并更新或插入数据
            dataCollectConfigureService.saveOrUpdateBatchData(Integer.valueOf(proId));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
